package ru.amse.baltijsky.javascheme.exporter.image;

import ru.amse.baltijsky.javascheme.util.Size;

import java.awt.*;
import java.io.File;
import java.io.IOException;

/**
 * An image exporter that draws schema tree in the specified graphics context when requested.
 */
public interface IImageExporter {
    /**
     * Draws schema tree in the graphics context starting from the specified point.
     *
     * @param g      graphics context
     * @param whereX x-coordinate of the place where to start the drawing
     * @param whereY y-coordinate of the place where to start the drawing
     */
    public void draw(Graphics g, int whereX, int whereY);

    /**
     * Returns the size of the image of the schema tree as if it were drawn in the current graphics context settings.
     *
     * @param g the graphics context
     * @return schema tree image size
     */
    public Size getImageSize(Graphics g);

    /**
     * Gets textual description for the schema tree drawn by this image exporter.
     *
     * @return textual description for the schema tree
     */
    public String getDescription();

    /**
     * Exports the image of the schema tree to the specified file.
     *
     * @param f          the file where to export the image
     * @param formatName informal name of the image format (eg., "jpg" or "bmp"). The name should match the one used
     *                   by {@code javax.imageio.ImageIO.write() } {@see javax.imageio.ImageIO#write()}
     * @throws IOException              if any error occurs while writing to the file
     * @throws IllegalArgumentException if the format name is unknown
     */
    public void exportToFile(File f, String formatName) throws IOException, IllegalArgumentException;

    /**
     * Sets whether the frames are drawn around the children subtrees.
     *
     * @param value the new value for the flag
     */
    public void setFramesSubtreeDecoration(boolean value);
}
